#include <iostream>
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 100;
int N, L[MAXN];
void solve();
int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> L[i];
    solve();
}

void solve() {
    priority_queue<int, vector<int>, greater<int> > q;
    for (int i = 0; i < N; i++) q.push(L[i]);
    int sum = 0;
    while (!q.empty()) {
        if (q.size() < 2) break;
        int i = q.top(); q.pop();
        int j = q.top(); q.pop();
        sum += i + j;
        q.push(i + j);
    }
    cout << sum << endl;
}